<?php
/**
 * View Modifica Artista - LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    21-apr-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/js/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript" src="/js/ckeditor/load-editor.js"></script>
<script type="text/javascript">
//<![CDATA[
    $(document).ready(function() {
	$.validator.addMethod(
	    "regex",
	    function(value, element, regexp) {
		return regexp.test(value);
	    }
	);

	$("#artistForm").validate({
	    invalidHandler: function(e, validator) {
		var errors = validator.numberOfInvalids();
		if (errors) {
		    $("li#errorLi").show();
		} else {
		    $("li#errorLi").hide();
		};
	    },
	    
	    // Assegna classe 'error' al <li> dell'elemento invalido
	    errorPlacement: function(error, element) {
		//console.log(element);
		element.parent("span").parent("div").parent("li").addClass("error");
		error.appendTo( element.parent("span").parent("div"));
	    },
	    submitHandler: function(form) {
		$('#salva').attr('disabled', 'disabled');
		form.submit();
	    },	    
	    errorElement: "p",
	    rules: {
		artist_name:{
		    required: true
		},
		artist_info:{
		    required: true
		},
		artist_official:{
		    url: true
		},
		artist_facebook:{
		    url: true
		},
		artist_myspace:{
		    url: true
		}
	    },
	    messages: {
		artist_name: {
		    required: "<?php echo  ERR_EMPTY ?>"
		},
		artist_info: {
		    required: "<?php echo  ERR_EMPTY ?>"
		},
		artist_official: {
		    url: "<?php echo  sprintf( ERR_FORMAT, 'Sito ufficiale' ) ?>"
		},
		artist_facebook: {
		    url: "<?php echo  sprintf( ERR_FORMAT, 'Facebook' ) ?>"
		},
		artist_myspace: {
		    url: "<?php echo  sprintf( ERR_FORMAT, 'Myspace' ) ?>"
		}
	    },
	    debug:true
	});

	// Risolve un bug d'integrazione tra jQuery e CKeditor
	$("#salva").click(function(){
			CKEDITOR.instances.artist_info.updateElement();
		});

	$( '#artist_info' ).ckeditor(function(){}, ckeditorConf );
	
	$('#artist_info').val('<?php echo  (addslashes($this->data['artist_info']))?>');

    });
    
    $("#salva").click(function() {
      validator.form();
    });    
    
    //]]>
</script>

<div class="info">
    <h2>Modifica Artista</h2>
    <div>Per inserire un nuovo artista...</div>
</div>
<!-- This <div> holds alert messages to be display in the sample page. -->
<div id="alerts">
    <noscript>
    <p>
	<strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
				support, like yours, you should still see the contents (HTML data) and you should
				be able to edit it normally, without a rich editor interface.
    </p>
    </noscript>
</div>
<form class="fab" name="artistForm" id="artistForm" action="/admin/artisti/edit/id/<?php echo $this->data['artist_id']?>" method="post" enctype="multipart/form-data" >
    <ul>
	<li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none'?>">
	    <h3 id="errorMsgLbl">Si Ã¨ verificato un problema durante l'invio del modulo.</h3>
	    <p id="errorMsg">
		Di seguito trovi evidenziati gli errori riscontrati.
	    </p>
	</li>
	
	<li class="<?php echo $this->errorMsg['artist_name'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['artist_name'] ? 'error' : ''?>">Nome<span class="req">*</span></label>
	    <div>
		<span>
		    <input id="artist_name" name="artist_name" class="field text large" type="text" maxlength="255" value="<?php echo $this->data['artist_name']?>" /> 
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['artist_name'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['artist_name']?></p>
	    <p id="instruct1" class="instruct">
		<img src="/uploads/artist_<?php echo $this->data['artist_id']?>.<?php echo $this->data['artist_image_ext']?>" style="width:100%" alt="Immagine Principale" title="Immagine Principale" />
	    </p>
	</li>
	
	<li class="<?php echo $this->errorMsg['artist_info'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['artist_info'] ? 'error' : ''?>">Info<span class="req">*</span></label>
	    <div>
		<span>
		    <textarea id="artist_info" name="artist_info" rows="10" cols="50"><?//=  htmlentities($this->data['post_text'])?></textarea>
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['artist_info'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['artist_info']?></p>
	</li>
	
	<li class="section">
	    <h3>Immagine Principale</h3>
	</li>
	
	<li class="complex <?php echo $this->errorMsg['artist_image'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['artist_image'] ? 'error' : ''?>">Immagine Principale</label>
	    <div>
		<span class="input">
		    <input class="field file" type="file" name="artist_image" id="artist_image" value="" />
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['artist_image'] ? 'display:block' : ''?>"><?php echo  $this->errorMsg['artist_image'] ?></p>
	    <p id="instruct1" class="instruct">
		<small>I formati ammessi sono
		    <br/><strong>PNG</strong>, <strong>JPG</strong>, <strong>GIF</strong> e <strong>BMP</strong></small>
	    </p>    
	</li>
	
	<li class="section">
	    <h3>Links</h3>
	</li>
	
	<li class="<?php echo $this->errorMsg['artist_official'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['artist_official'] ? 'error' : ''?>">Sito Ufficiale</label>
	    <div>
		<span>
		    <input id="artist_official" name="artist_official" class="field text medium" type="text" maxlength="255" value="<?php echo $this->data['artist_official']?>" /> 
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['artist_official'] ? 'display:block' : ''?>"><?php echo  $this->errorMsg['artist_official'] ?></p>
	    <p id="instruct1" class="instruct">
		<small>Inserisci eventuali link associati all'artista nella forma
		    <br/><strong> http://</strong>nomesito.tld</small>
	    </p>		    
	</li>
	<li class="<?php echo $this->errorMsg['artist_facebook'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['artist_facebook'] ? 'error' : ''?>">Facebook</label>
	    <div>
		<span>
		    <input id="artist_facebook" name="artist_facebook" class="field text medium" type="text" maxlength="255" value="<?php echo $this->data['artist_facebook']?>" /> 
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['artist_facebook'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['artist_facebook']?></p>
	</li>
	<li class="<?php echo $this->errorMsg['artist_myspace'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['artist_myspace'] ? 'error' : ''?>">MySpace</label>
	    <div>
		<span>
		    <input id="artist_myspace" name="artist_myspace" class="field text medium" type="text" maxlength="255" value="<?php echo $this->data['artist_myspace']?>" /> 
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['artist_myspace'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['artist_myspace']?></p>
	</li>
	<input id="artist_id" name="artist_id" type="hidden" value="<?php echo $this->data['artist_id']?>" />
    </ul>
    <div id="formButtons">
	<button id="salva" type="submit" name="salva" value="salva" class="button positive">
	    <img src="/images/admin/tick.png" alt="" />Salva
	</button>
    </div>
</form>
